﻿using System.Collections.Generic;
using System.Work.ProtoclBase;

namespace System.Work.ClientEngine.FPXH.Test
{
    public class Filter : TerminatorReceiveFilter<BufferedPackageInfo>
    {
        public Filter(byte[] terminator) : base(terminator)
        {
        }

        private byte[] GetFullData(IBufferStream bufferStream)
        {
            byte[] fulldata = new byte[((BufferList)bufferStream.Buffers).Total];
            var offset = 0;
            foreach (var b in bufferStream.Buffers)
            {
                b.CloneRange(0, b.Count).CopyTo(fulldata, offset);
                offset += b.Count;
            }
            return fulldata;
        }

        public override BufferedPackageInfo ResolvePackage(IBufferStream bufferStream)
        {
            //拼凑成完整的一帧数据
            return new BufferedPackageInfo("s", new List<ArraySegment<byte>>() { new ArraySegment<byte>(GetFullData(bufferStream)) });
        }
    }
}
